<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
        PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="${daoAllName}">
    <resultMap type="${beanAllName}" id="${beanName}Map">
        <id column="${pri}" property="${pri}"/>
    </resultMap>
    <insert id="save${beanName}" parameterType="${beanAllName}">
        insert into ${tableName}(
            <trim prefix="" suffixOverrides=",">
            <#list columns as col>
                <if test="${col.COLUMN_NAME} != null ${col.DATA_TYPE?matches(".*(int|date).*")?string(""," and ${col.COLUMN_NAME} != ''")}">
                ${col.COLUMN_NAME},
                </if>
            </#list>
            </trim>
        )values(
            <trim prefix="" suffixOverrides=",">
            <#list columns as col>
                <if test="${col.COLUMN_NAME} != null ${col.DATA_TYPE?matches(".*(int|date).*")?string(""," and ${col.COLUMN_NAME} != ''")}">
                ${r'#{'+col.COLUMN_NAME+'}'},
                </if>
            </#list>
            </trim>
        )
    </insert>
    <insert id="save${beanName}List" parameterType="java.util.ArrayList">
        insert into ${tableName} (
    <#list columns as col>
        <#if col_has_next!=true>
        ${col.COLUMN_NAME}
        <#else>
        ${col.COLUMN_NAME},
        </#if>
    </#list>
        ) VALUES
        <foreach collection="list" item="item" index="index" separator=",">
            (
        <#list columns as col>
            <#if col_has_next!=true>
            ${r'#{item.'+col.COLUMN_NAME+'}'}
            <#else>
            ${r'#{item.'+col.COLUMN_NAME+'}'},
            </#if>
        </#list>
            )
        </foreach>
    </insert>
    <!--  此处long作为通用的有待修改 -->
    <delete id="delete${beanName}ById" parameterType="${pri_type?contains("char")?string("string","long")}">
        delete from ${tableName} where ${pri}=${r'#{'+pri+'}'}
    </delete>
    <update id="update${beanName}ById" parameterType="${beanAllName}">
        update ${tableName}
        <set>
        <#list columns as col>
            <#if !(col.COLUMN_NAME?lower_case)?contains(pri)>
                <if test="${col.COLUMN_NAME} != null ${col.DATA_TYPE?matches(".*(int|date).*")?string(""," and ${col.COLUMN_NAME} != ''")}">
                ${col.COLUMN_NAME}=${r'#{'+col.COLUMN_NAME+'}'},
                </if>
            </#if>
        </#list>
        </set>
        where ${pri}=${r'#{'+pri+'}'}
    </update>
</mapper>